package com.bwie.house.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.common.utils.PageUtils;
import com.bwie.common.utils.Query;

import com.bwie.house.dao.AddressDao;
import com.bwie.house.entity.AddressEntity;
import com.bwie.house.service.AddressService;


@Service("addressService")
public class AddressServiceImpl extends ServiceImpl<AddressDao, AddressEntity> implements AddressService {

    @Override
    public PageUtils queryPageGXL(Map<String, Object> params,String id) {

        QueryWrapper<AddressEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("parent_id",id);

        IPage<AddressEntity> page = this.page(
                new Query<AddressEntity>().getPage(params),
            wrapper
        );

        return new PageUtils(page);
    }



    @Override
    public List<AddressEntity> queryPage1(Map<String, Object> params) {
        String parentId = (String) params.get("parentId");
        QueryWrapper<AddressEntity> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(parentId)){
            wrapper.eq("parent_id",parentId);
        }
        return baseMapper.selectList(wrapper);
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        QueryWrapper<AddressEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("parent_id",0);

        IPage<AddressEntity> page = this.page(
                new Query<AddressEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public List<AddressEntity> xian31() {
        QueryWrapper<AddressEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("level",3);
        return baseMapper.selectList(wrapper);
    }

}